package com.ibeeking.found.cms.api.feign.fallback;

import com.ibeeking.found.cms.api.common.dto.*;
import com.ibeeking.found.cms.api.common.dto.*;
import com.ibeeking.found.cms.api.common.query.GoodsByGroupQuery;
import com.ibeeking.found.cms.api.common.query.GoodsFeignPageQuery;
import com.ibeeking.found.cms.api.feign.CmsGoodsFeignBClient;
import com.ibeeking.nematos.utils.base.page.Page;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class CmsGoodsFeignBFallbackFactory implements FallbackFactory<CmsGoodsFeignBClient> {
    @Override
    public CmsGoodsFeignBClient create(Throwable throwable) {
        return new CmsGoodsFeignBClient() {

            @Override
            public ResponseResult<List<GoodsDTO>> listByGoods(List<Long> goodsIds) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询商品信息失败", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<GoodsCategoryDTO>> goodsCategoryEffectiveRootDtoList() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询商品类目根列表失败", Collections3.emptyList());
            }

            @Override
            public ResponseResult<Page<GoodsPageDTO>> feignPageList(GoodsFeignPageQuery goodsFeignPageQuery) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询商品分页列表!");
            }

            @Override
            public ResponseResult<List<GoodsVoDTO>> queryGoodsByGroup(GoodsByGroupQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据商品分组查询商品失败!", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<GoodsGroupBaseDTO>> queryGoodsGroupByIds(List<Long> groupIds) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据商品分组id查询商品分组失败!", Collections3.emptyList());
            }
        };
    }
}
